<template>
<div>
    <el-form size="small" :model="inputForm" ref="inputForm" v-loading="loading" :disabled="formReadOnly"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="24">
            <el-form-item label="申请人" prop="proposer.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.proposer.id" @getValue='(value) => {inputForm.proposer.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="创建部门" prop="createDepartment.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="createDepartment"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.createDepartment.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.createDepartment.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="项目部" prop="projectDepartment.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="projectDepartment"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.projectDepartment.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.projectDepartment.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="分公司" prop="filiale.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="filiale"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.filiale.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.filiale.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="分包合同名称" prop="subpackageContractName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.subpackageContractName" placeholder="请填写分包合同名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="分包合同编号" prop="subcontractNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.subcontractNo" placeholder="请填写分包合同编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="乙方名称" prop="partybName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.partybName" placeholder="请填写乙方名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="乙方联系人" prop="partybLinkman"
                :rules="[
                 ]">
              <el-input v-model="inputForm.partybLinkman" placeholder="请填写乙方联系人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="乙方联系人电话" prop="partybPhone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.partybPhone" placeholder="请填写乙方联系人电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="分包合同金额" prop="subcontractAmount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.subcontractAmount" placeholder="请填写分包合同金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="分包合同总额" prop="totalSubcontractValue"
                :rules="[
                 ]">
              <el-input v-model="inputForm.totalSubcontractValue" placeholder="请填写分包合同总额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="收款单位" prop="payee"
                :rules="[
                 ]">
              <el-input v-model="inputForm.payee" placeholder="请填写收款单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="开户行" prop="openingBank"
                :rules="[
                 ]">
              <el-input v-model="inputForm.openingBank" placeholder="请填写开户行"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="账号" prop="accountNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.accountNumber" placeholder="请填写账号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="生效日期" prop="effectiveDate"
                :rules="[
                 ]">
                <el-date-picker
                      v-model="inputForm.effectiveDate"
                      type="datetime"
                      style="width: 100%;"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="终止日期" prop="expiryDate"
                :rules="[
                 ]">
                <el-date-picker
                      v-model="inputForm.expiryDate"
                      type="datetime"
                      style="width: 100%;"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="甲方联系人" prop="partyaLinkman"
                :rules="[
                 ]">
              <el-input v-model="inputForm.partyaLinkman" placeholder="请填写甲方联系人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="甲方联系人电话" prop="partyaPhone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.partyaPhone" placeholder="请填写甲方联系人电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="合同签订日期" prop="contractSigningDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.contractSigningDate" placeholder="请填写合同签订日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="合同负责人" prop="contractOfficer"
                :rules="[
                 ]">
              <el-input v-model="inputForm.contractOfficer" placeholder="请填写合同负责人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="合同状态" prop="contractState"
                :rules="[
                 ]">
              <el-input v-model="inputForm.contractState" placeholder="请填写合同状态"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="是否提交归档" prop="isSubmitPigeonhole"
                :rules="[
                 ]">
                <el-select v-model="inputForm.isSubmitPigeonhole" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="归档日期" prop="pigeonholeDate"
                :rules="[
                 ]">
                <el-date-picker
                      v-model="inputForm.pigeonholeDate"
                      type="datetime"
                      style="width: 100%;"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="是否签出" prop="isSignOff"
                :rules="[
                 ]">
                <el-select v-model="inputForm.isSignOff" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="签出日期" prop="signOffDate"
                :rules="[
                 ]">
                <el-date-picker
                      v-model="inputForm.signOffDate"
                      type="datetime"
                      style="width: 100%;"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="归档人姓名" prop="pigeonholeName.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.pigeonholeName.id" @getValue='(value) => {inputForm.pigeonholeName.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="是否提交" prop="isSubmit"
                :rules="[
                 ]">
                <el-select v-model="inputForm.isSubmit" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="补充合同(自关联字段)" prop="children.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择补充合同(自关联字段)"
            labelName = 'partybName'
            labelValue = 'id'
            :value = "inputForm.children.id"
            :limit="1"
            @getValue='(value) => {inputForm.children.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'partybName',
              label: '乙方名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'partybName',
              label: '乙方名称'
            }
            ]"
            dataListUrl="/epc/contractsubpackage/contractSubpackage/list"
            entityBeanName="contractSubpackage"
            queryEntityUrl="/epc/contractsubpackage/contractSubpackage/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        loading: false,
        inputForm: {
          id: '',
          proposer: {
            id: ''
          },
          createDepartment: {
            id: ''
          },
          projectDepartment: {
            id: ''
          },
          filiale: {
            id: ''
          },
          subpackageContractName: '',
          subcontractNo: '',
          partybName: '',
          partybLinkman: '',
          partybPhone: '',
          subcontractAmount: '',
          totalSubcontractValue: '',
          payee: '',
          openingBank: '',
          accountNumber: '',
          effectiveDate: '',
          expiryDate: '',
          partyaLinkman: '',
          partyaPhone: '',
          contractSigningDate: '',
          contractOfficer: '',
          contractState: '',
          isSubmitPigeonhole: '',
          pigeonholeDate: '',
          isSignOff: '',
          signOffDate: '',
          pigeonholeName: {
            id: ''
          },
          isSubmit: '',
          children: {
            id: ''
          },
          remarks: ''
        }
      }
    },
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      }
    },
    components: {
      UserSelect,
      SelectTree,
      GridSelect
    },
    watch: {
      'businessId': {
        handler (newVal) {
          if (this.businessId) {
            this.init(this.businessId)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        },
        immediate: true,
        deep: false
      }
    },
    methods: {
      init (id) {
        if (id) {
          this.loading = true
          this.inputForm.id = id
          this.$nextTick(() => {
            this.$refs.inputForm.resetFields()
            this.$http({
              url: `/epc/contractsubpackage/contractSubpackage/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.contractSubpackage)
              this.loading = false
            })
          })
        }
      },
      // 表单提交
      saveForm (callback) {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/contractsubpackage/contractSubpackage/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                callback(data.businessTable, data.businessId)
              }
            })
          }
        })
      }
    }
  }
</script>